<%@ page import="com.ld.businesscard_manage.service.BusinessCardService" %>
<%@ page import="com.ld.businesscard_manage.service.impl.UserServiceImpl" %>
<%@ page import="com.ld.businesscard_manage.service.UserService" %>
<%@ page import="com.ld.businesscard_manage.service.impl.BusinessCardServiceImpl" %>
<%@ page import="com.ld.businesscard_manage.bean.User" %>
<%@ page import="org.apache.commons.codec.digest.DigestUtils" %><%--
  Created by IntelliJ IDEA.
  User: 刘邓
  Date: 2023-06-18
  Time: 8:45
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>修改结果</title>
</head>
<body>
<%!
    private UserService userService = new UserServiceImpl();
    private BusinessCardService cardService = new BusinessCardServiceImpl();
%>
<%
    request.setCharacterEncoding("utf-8");
    User user0 = (User)(session.getAttribute("user"));
    Integer id = user0.getId();
    String userName = user0.getUsername();
    String userName0 = userName;
    String password = DigestUtils.md5Hex(request.getParameter("password"));
    Integer status = user0.getStatus();
    if (!request.getParameter("username").equals("")) {
        userName = request.getParameter("username");
    };
    User userByName = userService.getUserByName(userName);
    if(userByName != null && !userByName.getUsername().equals(userName0)){
        out.println("该用户已经存在");
    }else {
        User user = new User(id, userName, password, status);
        int i = userService.changeUserById(user);
        int j = cardService.changeCardsByAccount(user,userName0);
        if (i == 0 || j == 0) {
            out.println("<h1>修改失败,请稍后重试</h1>");
        } else {
            out.println("<h1>修改成功</h1>");
        }
    }
    out.println("<a href='/home/application.jsp'>返回个人名片管理页</a>");
%>
</body>
</html>
